package edu.lingnan.lmlibrary.controller;


import edu.lingnan.lmlibrary.common.JSONResult;
import edu.lingnan.lmlibrary.dto.BookingInfo;
import edu.lingnan.lmlibrary.dto.BookingSeatInfo;
import edu.lingnan.lmlibrary.dto.FloorSeats;
import edu.lingnan.lmlibrary.service.SeatService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张晓航
 * @since 2022-02-26
 */
@RestController
@RequestMapping("/seat")
@CrossOrigin
public class SeatController {
    @Autowired
    private SeatService seatService;
    @Autowired
    private RestTemplate restTemplate;
    @GetMapping("/getSeatsByFloorId/{fId}")
    @ApiOperation("根据教室编号请求教室桌子座位信息")
    public JSONResult<List<FloorSeats>> getSeatsByFloorId(@ApiParam("教室编号") @PathVariable Integer fId){
        return seatService.getDeskAndSeatCountsByFloorId(fId);
    }

    @PostMapping(value = "/bookingSeat")
    @ApiOperation(value = "预约座位")

    public JSONResult<BookingSeatInfo> bookingSeat(@RequestBody BookingInfo bookingInfo){
        return seatService.bookingSeatBySeatIdAndSid(bookingInfo.getSeatId(), bookingInfo.getSId(), restTemplate);
    }
}

